<template>
  <!-- 一条文章单元格 -->
  <div>
    <van-cell>
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ articleItem.title }}</span>
          <!-- 单图 -->
            <!-- lazy-load -->
          <van-image
            v-if="articleItem.cover.type === 1"
            class="thumb"
            :sec="articleItem.cover.images[0]"
            alt=""
          >
            <template v-slot:loading>
              <van-loading type="spinner" size="20" />
            </template>
          </van-image>
        </div>
        <!-- 多图 -->
        <div class="thumb-box" v-if="articleItem.cover.type > 1">
          <van-image
            v-for="(imgUrl, index) in articleItem.cover.images"
            :key="index"
            class="thumb"
            :src="imgUrl"
            alt=""
          >
          <template v-slot:loading>
            <van-loading type="spinner" size="20" />
          </template>
          </van-image>
        </div>
      </template>

      <template #label>
        <div class="label-box">
          <div>
            <span>{{ articleItem.aut_name }}</span>
            <span>{{ articleItem.comm_count }}评论</span>
            <span>{{ formatTime(articleItem.pubdate) }}</span>
          </div>
          <van-icon name="cross" @click.stop="show = true" />
        </div>
      </template>
    </van-cell>

    <!-- 反馈面板 -->
    <van-action-sheet
      v-model="show"
      :actions="actions"
      @select="onSelect"
      @cancel="cancelFn"
      @close="closeFn"
      get-container="body"
      :cancel-text="bottomText"
    />
  </div>
</template>

<script>
import { timeAgo } from "@/utils/date.js";
import { firstActions, secondActions } from "@/utils/report.js";
export default {
  props: ["articleItem"],
  data() {
    return {
      formatTime: timeAgo,
      show: false,
      actions: firstActions,
      bottomText: "取消",
    };
  },
  methods: {
    onSelect(action) {
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起
      if (action.name === "反馈垃圾内容") {
        this.actions = secondActions;
        this.bottomText = "返回";
      } else if(action.name = '不感兴趣') {
        this.$emit('disLikeEv', this.articleItem.art_id)
        this.show = false;
      } else {
        this.$emit('reportEv', this.articleItem.art_id, action.value)
        // this.actions = firstActions
        this.show = false
      }
    },
    cancelFn() {
      if (this.bottomText == "返回") {
        this.show = true;
        this.actions = firstActions;
        this.bottomText = "取消";
      }
    },
    closeFn() {
      this.actions = firstActions
      this.bottomText = "取消";
    }
  },
};
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}

/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>